package com.hawthorn.admin.repository.provider;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hawthorn.admin.model.po.SysMenuPO;
import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

import java.util.Map;

/**
 * <p>todo 菜单管理provider</p>
 * @author: WCZ
 * @created: 2022/7/7$ 14:03$
 * @version v1.0.1
 */

public class SysMenuSqlProvider implements ProviderMethodResolver
{
  /**
   * <p>todo 查询</p >
   * @param page 分页条件
   * @param qc  * @return : java.lang.String
   * @author: wcz
   * @date: 2022/7/11 11:21
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/11 wcz v1.0.1 init
   */
  public String findMenu(Page<Map<String, Object>> page, String qc)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	id,\n ");
    sql.append(" 	code,\n ");
    sql.append(" 	title,\n ");
    sql.append(" 	title_en titleEn,\n ");
    sql.append(" 	sub_count 	subCount,\n ");
    sql.append(" 	parent_id 	parentId,\n ");
    sql.append(" 	parent_code 	parentCode,\n ");
    sql.append(" 	parent_title 	parentTitle,\n ");
    sql.append(" 	url,\n ");
    sql.append(" 	component,\n ");
    sql.append(" 	component_name 	componentName,\n ");
    sql.append(" 	path,\n ");
    sql.append(" 	perms,\n ");
    sql.append(" 	type,\n ");
    sql.append(" 	icon,\n ");
    sql.append(" 	order_num 	orderNum,\n ");
    sql.append(" 	external,\n ");
    sql.append(" 	status,\n ");
    sql.append(" 	biz_type, \n ");
    sql.append(" 	hidden, \n ");
    sql.append(" 	cache \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_menu\n ");
    sql.append(" 	where\n ");
    sql.append(qc);
    return sql.toString();
  }

  /***
   * <p>todo 校验重复</p >
   * @param sysMenuPO  * @return : java.lang.String
   * @author: wcz
   * @date: 2022/7/11 11:21
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/11 wcz v1.0.1 init
   */
  public String checkMenu(SysMenuPO sysMenuPO)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	count(*) \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_menu \n ");
    sql.append(" WHERE title = '" + sysMenuPO.getTitle() + "' \n");
    return sql.toString();
  }
/**
 * <p>todo 导出</p >
 * @param fields 导出列表头
 * @param qc  * @return : java.lang.String
 * @author: wcz
 * @date: 2022/7/11 11:21
 * @version: 1.0.1
 * Modification History:
 * Date Author Version Description
 * -----------------------------------------------------------
 * 2022/7/11 wcz v1.0.1 init
 */
  public String exportMenu(String fields, String qc)
  {
    StringBuffer sql = new StringBuffer();
    sql.append("select ");
    sql.append(fields);
    sql.append(" from \n");
    sql.append(" 	sys_menu a\n ");
    sql.append("where ");
    sql.append(qc);
    return sql.toString();
  }
  /**
   * <p>todo 修改状态</p >
   * @param id  * @return : java.lang.String
   * @author: wcz
   * @date: 2022/7/14 14:25
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/14 wcz v1.0.1 init
   */
  public String findById(Long id)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	count( 1 ) \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_menu \n ");
    sql.append(" where\n ");
    sql.append(" 	parent_id = '"+id+"'\n ");
    sql.append(" 	and `status` = 100201\n ");
    return sql.toString();
  }


}
